<?php

namespace app\http\middleware;
use think\facade\Session;


class Before
{
    public function handle($request, \Closure $next)
    {   

        // die;
        // var_dump(Session::has('admin_name'));die;
        if(!Session::has('admin_name'))
        {
            redirect('/admin/index/login');
        }   
        // echo '<pre>';
        //是否石超级管理员，直接退出中间件

        if(Session::get('path')=='root'){
            return $next($request);
        }
        
        $url_path = Session::get('path');

        $url = array_column($url_path , 'url_path');


        $white = ['/admin/index/index','/admin/index/welcome'];

        $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO']:'/admin/index/index';
        // echo '<pre>';
        // var_dump($url, $path);
        if(!in_array($path,array_merge($white, $url)))
        {
           die('没有权限');
        }

        $request->hello = 'ThinkPHP';
        return $next($request);
    }
}
